package com.power.controller;

import com.power.common.Contants;
import com.power.ov.ResultData;
import com.power.service.InformationService;
import com.power.service.impl.InformationServiceImpl;
import com.power.utils.WriterUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/09 11:08
 * Description:
 * Version: V1.0
 */
@WebServlet("/eliminate.do")
public class EliminateController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        InformationService in=new InformationServiceImpl();
        ResultData resultData=new ResultData();
        try {
            resultData=in.eliminateAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        WriterUtil.getWriter(resp,resultData);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account=req.getParameter("account");
        InformationService in=new InformationServiceImpl();
        ResultData resultData=new ResultData();
        try {
            resultData=in.eliminateByAccount(account);
        } catch (SQLException e) {
            resultData.setCode(Contants.EXCEPTION);
            resultData.setMsg("系统开小差了....");
            e.printStackTrace();
        }
        WriterUtil.getWriter(resp,resultData);
    }
}
